//
//  RCNetRequestManager.h
//  RCNetRequestProject
//
//  Created by kabu on 2017/7/18.
//  Copyright © 2017年 RC. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "RCHttpRequestSerialization.h"
#import "RCHttpResponseSerialization.h"
#import <AFNetworking.h>
#define ERRER_CODE_NOTNETWORK -250
#define ERRER_MESSAGE_NOTNETWORK @"没有网络"

typedef void (^RCNetRequestSuccessBlock)(id result);
typedef void(^RCNetRequestFailureBlock)(id failure);
@protocol RCNetRequest <NSObject>

/**
 GET 请求方法

 @param url URLString
 @param params 参数
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (NSURLSessionTask*)getWithUrl:(NSString*)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;

/**
 POST 请求方法

 @param url URLString
 @param params 参数
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (id)postWithUrl:(NSString*)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;

/**
 PUT 请求方法

 @param url URLString
 @param params 参数
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (id)putWithUrl:(NSString*)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;

/**
 DELETE 请求方法

 @param url URLString
 @param params 参数
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (id)deleteWithUrl:(NSString*)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;

/**
 DOWNLOAD 下载文件

 @param url URLString
 @param params 参数
 @param aLocal 本地存储地址
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (id)downloadWithUrl:(NSString*)url params:(id)params atLocal:(NSURL*)aLocal success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;

/**
 UPLOAD 上传文件

 @param url URLString
 @param params 参数
 @param wLocal 待上传文件地址
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
- (id)uploadWithUrl:(NSString*)url params:(id)params withLocal:(NSURL*)wLocal success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;
/**
 以post方式上传文件
 
 @param url URL
 @param params 参数
 @param aFormData 数据
 @param mimeType 类型 例如"image/jpg"、"image/png"
 @param fileName 文件全称
 @param name 名称
 @param aSuccess 成功回调
 @param aFailure 失败回调
 @return 请求实例
 */
-(id)postWithUrl:(NSString *)url params:(id)params formData:(NSData*)aFormData mimeType:(NSString*)mimeType fileName:(NSString*)fileName name:(NSString*)name success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure;
@end
@interface RCHttpRequest : NSObject<RCNetRequest>
@property (strong, nonatomic) id <RCURLRequestSerialization> requestSerialization;
@property (strong, nonatomic) id <RCURLResponseSerialization> responseSerialization;
@property (assign, nonatomic) NSTimeInterval timeoutInterval;
@property (assign, nonatomic) BOOL isAllowHttps;
+ (instancetype)manager;

/**
 获取当前网络状态

 @param url URL地址
 @return 网络状态
 */
- (AFNetworkReachabilityStatus)netWorkStatusOfUrl:(NSString*)url;

/**
 设置请求头

 @param value 值
 @param field key
 */
- (void)setValue:(NSString*)value forHTTPHeaderField:(NSString *)field;


/**
 Request初始化

 @param method 请求方式
 @param URLString URL地址
 @param parameters 参数
 @param error 错误
 @return Request
 */
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method URLString:(NSString *)URLString parameters:(id)parameters error:(NSError * __autoreleasing *)error;

/**
 返回结果处理

 @param response Response
 @param data 数据
 @param error 出错
 @return 对象
 */
- (id)responseObjectForResponseSerialization:(NSURLResponse*)response data:(NSData*)data error:(NSError * __autoreleasing *)error;


/**
 服务端的SSL证书

 @return 证书数据
 */
- (NSData*)serverCerData;

/**
 BaseURL

 @return 基础url
 */
- (NSString*)serverHostUrl;
@end
